package com.admin.service.impl;

import com.admin.entity.AdminRole;
import com.admin.mapper.AdminRoleMapper;
import com.admin.service.IAdminRoleService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {
    @Autowired
    private AdminRoleMapper adminRoleMapper;

    public IPage findRoleByAdmin(int page, int size, String text) {
        IPage iPage = new Page(page, size);
        IPage<Map> maps = adminRoleMapper.findRoleByAdmin(iPage, text);
        return maps;
    }
    public List<Map> findAllRole(){
        List<Map> maps = adminRoleMapper.findAllRole();
        return maps;
    }
    public Map adminRoleSave(String adminId, String roleId){
        AdminRole adminRole = new AdminRole();
        int adminIdInt = Integer.parseInt(adminId);
        int roleIdInt = Integer.parseInt(roleId);
        adminRole.setAdminId(adminIdInt);
        adminRole.setRoleId(roleIdInt);
        int n = adminRoleMapper.insert(adminRole);
        Map map = new HashMap();
        map.put("n",n);
        map.put("id",adminRole.getAdminRoleId());
        return map;
    }
    public int adminRoleDel(String adminRoleId){
        int n = adminRoleMapper.deleteById(Integer.parseInt(adminRoleId));
        return n;
    }
}
